import { createRouter, createWebHistory } from "vue-router";
const notfound = () => import("../views/404.vue");
const Home = () => import("../views/home/Home.vue");
const My = () => import("../views/my/My.vue");
const Register = () => import("../views/profile/Register.vue");
const Detail = () => import("../views/detail/Detail");
const Login = () => import("../views/profile/Login.vue");
const Account = () => import("../views/account/Account.vue");
const Buy = () => import("../views/buy/Buy.vue");
const Pay = () => import("../views/pay/Pay.vue");
const Final = () => import("../views/final/Final.vue");
const Debit = () => import("../views/debit/Debit.vue");
const Deposit = () => import("../views/deposit/Deposit.vue");
const Subscribe = () => import("../views/subscribe/Subscribe.vue");

const routes = [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/:catchAll(.*)",
    name: "404",
    component: notfound,
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
    meta: {
      title: "三湘银行",
    },
  },
  {
    path: "/my",
    name: "My",
    component: My,
    meta: {
      title: "我的",
    },
  },
  {
    path: "/register",
    name: "Register",
    component: Register,
    meta: {
      title: "账号注册",
    },
  },
  {
    path: "/detail",
    name: "Detail",
    component: Detail,
    meta: {
      title: "订单详情",
    },
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
    meta: {
      title: "用户登录",
    },
  },
  {
    path: "/account",
    name: "Account",
    component: Account,
    meta: {
      title: "我的账户",
    },
  },
  {
    path: "/buy",
    name: "Buy",
    component: Buy,
    meta: {
      title: "完善购买信息",
    },
  },
  {
    path: "/pay",
    name: "Pay",
    component: Pay,
    meta: {
      title: "确认订单",
    },
  },
  {
    path: "/final",
    name: "Final",
    component: Final,
    meta: {
      title: "",
    },
  },
  {
    path: "/debit",
    name: "Debit",
    component: Debit,
    meta: {
      title: "我的贷款",
    },
  },
  {
    path: "/deposit",
    name: "Deposit",
    component: Deposit,
    meta: {
      title: "我的存款",
    },
  },
  {
    path: "/subscribe",
    name: "Subscribe",
    component: Subscribe,
    meta: {
      title: "我的预约",
    },
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});
router.beforeEach((to, from, next) => {
  next();
  document.title = to.meta.title;
});

export default router;
